<template>
  <div class="table-box">
    <div class="table-search">
      <el-form :inline="true" :model="form">
        <el-form-item>
          <el-input
            clearable
            placeholder="商户ID"
            v-model="form.merchant_id"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            clearable
            placeholder="订单流水号"
            v-model="form.order_no"
            style="width: 250px"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            placeholder="收款人"
            v-model="form.receive_card_name"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            placeholder="收款账号"
            v-model="form.receive_card_number"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="form.status"
            placeholder="订单状态"
            clearable
            style="width: 120px"
          >
            <el-option label="成功" value="1"></el-option>
            <el-option label="处理中" value="0"></el-option>
            <el-option label="失败" value="2"></el-option>
            <el-option label="取消" value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="form.sys_review_status"
            placeholder="系统审核状态"
            clearable
            style="width: 150px"
          >
            <el-option label="成功" value="1"></el-option>
            <el-option label="审核中" value="0"></el-option>
            <el-option label="失败" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="提现时间">
          <el-date-picker
            clearable
            v-model="form.timeData"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="截止日期"
            :default-time="pickerDefaultTime"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onQuery">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="card content-box">
      <div class="table">
        <el-table :data="tableData" border v-loading="loading">
          <el-table-column prop="id" label="ID" align="center" />
          <el-table-column
            prop="merchant_id"
            label="商户id"
            align="center"
            width="110"
          />
          <el-table-column
            prop="merchant_name"
            label="商户名称"
            align="center"
            width="150"
          />
          <el-table-column
            prop="order_no"
            label="订单流水号"
            align="center"
            width="150"
          />
          <el-table-column label="金额" align="center">
            <template #default="scope"
              >{{ scope.row.amount }} {{ scope.row.currency }}</template
            >
          </el-table-column>
          <el-table-column prop="fee" label="手续费" align="center" />
          <el-table-column label="付款信息" align="left" width="300">
            <template #default="scope">
              <div
                v-for="x in scope.row.sends"
                style="border-bottom: 1px solid #eeeeee"
              >
                <p>付款银行：{{ x.send_bank }} {{ x.send_branch }}</p>
                <p>付款账号：{{ x.send_card_number }}</p>
                <p>付款人：{{ x.send_card_name }}</p>
                <p>付款金额：{{ x.send_amount }} {{ x.send_currency }}</p>
                <p>付款时间：{{ formatDates(x.send_pay_time) }}</p>
                <p v-if="x.send_swift_code">Swift码：{{ x.send_swift_code }}</p>
                <p v-if="x.send_extended">补充信息：{{ x.send_extended }}</p>
                <p v-if="x.payment_way">支付方式：{{ x.payment_way }}</p>
                <p v-if="x.payment_order_no">
                  支付流水号：{{ x.payment_order_no }}
                </p>
                <p v-if="x.attachments">
                  <el-image
                    style="width: 50px; height: 50px"
                    v-for="i in x.attachments"
                    :src="i"
                    alt
                    fit="fill"
                    :preview-src-list="[i]"
                    :preview-teleported="true"
                  />
                </p>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="收款信息" align="left" width="300">
            <template #default="scope">
              <p>收款名称：{{ scope.row.receive_name }}</p>
              <p>
                收款银行：{{ scope.row.receive_bank }}
                {{ scope.row.receive_branch }}
              </p>
              <p>收款地址：{{ scope.row.receive_bank_address }}</p>
              <p>收款账号：{{ scope.row.receive_card_number }}</p>
              <p>收款姓名：{{ scope.row.receive_card_name }}</p>
              <p>Swift码：{{ scope.row.receive_swift_code }}</p>
              <p v-if="scope.row.receive_extended">
                补充信息：{{ scope.row.receive_extended }}
              </p>
            </template>
          </el-table-column>
          <el-table-column
            prop="mer_review_status"
            label="商户审核"
            align="center"
          >
            <template #default="scope">
              <el-tag
                :type="
                  scope.row.mer_review_status == 1
                    ? 'success'
                    : scope.row.mer_review_status == 2
                    ? 'danger'
                    : 'warning'
                "
              >
                {{
                  scope.row.mer_review_status == 1
                    ? "已审核"
                    : scope.row.mer_review_status == 2
                    ? "拒绝"
                    : "未审核"
                }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column
            prop="sys_review_status"
            label="系统审核"
            align="center"
          >
            <template #default="scope">
              <el-tag
                :type="
                  scope.row.sys_review_status == 1
                    ? 'success'
                    : scope.row.sys_review_status == 0
                    ? 'warning'
                    : 'danger'
                "
              >
                {{
                  scope.row.sys_review_status == 1
                    ? "已审核"
                    : scope.row.sys_review_status == 2
                    ? "拒绝"
                    : "未审核"
                }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="sys_auditor" label="审核人" align="center" />
          <el-table-column
            prop="sys_audit_time"
            label="审核时间"
            :formatter="formatterTime"
            align="center"
            width="180"
          ></el-table-column>
          <el-table-column
            prop="createtime"
            label="提现时间"
            :formatter="formatterTime"
            align="center"
            width="180"
          ></el-table-column>
          <el-table-column prop="status" label="订单状态" align="center">
            <!--0:处理中;1:成功;2:失败 3:取消-->
            <template #default="scope">
              <el-tag
                :type="
                  scope.row.status == 1
                    ? 'success'
                    : scope.row.status == 0
                    ? 'warning'
                    : 'danger'
                "
              >
                {{
                  scope.row.status == 1
                    ? "成功"
                    : scope.row.status == 2
                    ? "失败"
                    : scope.row.status == 3
                    ? "取消"
                    : "处理中"
                }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="description" label="备注" align="center" />
        </el-table>
        <div class="table-pagination">
          <el-pagination
            :current-page="pageable.pageNum"
            :page-size="pageable.pageSize"
            :page-sizes="[10, 25, 50, 100]"
            :background="true"
            layout="total, sizes, prev, pager, next, jumper"
            :total="pageable.total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, reactive } from "vue";
import { formatterTime, pickerDefaultTime, formatDates } from "@/utils/utils";
import { withdrawListApi } from "@/api/ExAssistant/withdraw";

const loading = ref(false);
const tableData = ref([]);

const formData = {
  merchant_id: "",
  order_no: "",
  timeData: [],
};
const form = reactive({ ...formData });
const pageable = reactive({
  pageNum: 1,
  pageSize: 10,
  total: 0,
});

//参数
const param = () => {
  return {
    page: pageable.pageNum,
    pagesize: pageable.pageSize,
    order_type: 1,
    merchant_id: form.merchant_id,
    order_no: form.order_no,
    receive_card_name: form.receive_card_name,
    receive_card_number: form.receive_card_number,
    status: form.status,
    sys_review_status: form.sys_review_status,
  };
};

// 获取表格数据
const getTbaleData = async () => {
  loading.value = true;

  try {
    const res = await withdrawListApi(param());
    loading.value = false;
    tableData.value = res.data.results;
    pageable.total = res.data.count;
  } catch (error) {
    loading.value = false;
  }
};
//查询
const onQuery = async () => {
  getTbaleData();
};
// 条数
const handleSizeChange = (number) => {
  pageable.pageSize = number;
  getTbaleData();
};

// 页码
const handleCurrentChange = (number) => {
  pageable.pageNum = number;
  getTbaleData();
};
onMounted(() => {
  getTbaleData();
});
</script>
